package com.wolfman.socket.server.service.impl;

import com.alibaba.fastjson.JSON;
import com.wolfman.socket.server.mapper.PersonMapper;
import com.wolfman.socket.server.mapper.impl.PersonMapperImpl;
import com.wolfman.socket.server.pojo.Log;
import com.wolfman.socket.server.pojo.Person;
import com.wolfman.socket.server.service.LogService;
import com.wolfman.socket.server.service.PersonService;

import java.time.LocalDateTime;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2022/11/26 15:57
 * @Email 2370032534@qq.com
 */
public class PersonServiceImpl implements PersonService {

    private static PersonMapper personMapper = new PersonMapperImpl();

    private static LogService logService = new LogServiceImpl();

    @Override
    public Object saverPerson(Person person) {
        try {
            return personMapper.saverPerson(person);
        } catch (Exception e) {
            //记录失败日志
            logService.saveLog(new Log(null, "saverPerson", e.getMessage(), JSON.toJSONString(person), LocalDateTime.now()));
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public Object selectPerson(Person person) {
        return personMapper.selectPersonById(person.getId());
    }
}
